package com.gitee.simons.system.controller;

import com.gitee.simons.common.utils.GsonUtil;
import com.gitee.simons.system.fegin.TestFeginClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jsm
 * @date 2019/5/30 15:32
 * @Description
 */
@RestController
@RefreshScope
@Slf4j
@Api(tags = {"测试信息"})
@RequestMapping("/test")
public class TestController implements TestFeginClient{

    @Value("${info.test}")
    private String test;

    @Autowired
    private TestFeginClient testFeginClient;

    @GetMapping("/test")
    @ApiOperation("测试接口")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @Override
    public String test(Authentication authentication) {
        log.info("显示的信息为：----------------------" + test);

        log.info(GsonUtil.toJson(authentication));
        return test;
    }

    @GetMapping("/testPermission")
    @ApiOperation("测试权限信息")
    public String testPermission(Authentication authentication) {
        return testFeginClient.test(authentication);
    }
}
